package cn.com.flat.mybatis.bean;

import cn.com.flat.utils.PackageUtil;
import org.apache.log4j.Logger;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * 标题: 修改typeAliasesPackage
 * <p>
 * 描述: 通过通配符方式配置typeAliasesPackage
 * <p>
 * 版权：Copyright (c) 2016
 * <p>
 *
 * @author 张顺
 * @version 1.0
 * @created 2016/11/16/22:50
 */
public class AliaseSqlsessionFactoryBean extends SqlSessionFactoryBean{

    private static Logger logger = Logger.getLogger(AliaseSqlsessionFactoryBean.class);
    @Override
    public void setTypeAliasesPackage(String typeAliasesPackage) {
        Set<String> set = PackageUtil.deCodePackageName(typeAliasesPackage);
        if (set.size()>0){
                super.setTypeAliasesPackage(org.apache.commons.lang3.StringUtils.join(set.toArray(),","));
        }else{
            throw new RuntimeException("参数typeAliasesPackage:"+typeAliasesPackage+",未找到任何包");
        }
    }
}
